<template>
    <div class="common-layout">
        <el-container class="main-container">
            <el-header class="main-header">
                <div class="header-left">
                    <div class="logo-section">
                        <el-icon class="logo-icon">
                            <WindPower />
                        </el-icon>
                        <h1 class="system-title">颐养中心管理系统</h1>
                    </div>
                </div>
                <div class="header-right">
                    <el-dropdown split-button type="primary" class="user-dropdown" @click="handleClick">
                        <el-icon><User /></el-icon>
                        <span>欢迎：{{userName}}</span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item>
                                    <el-icon><Setting /></el-icon>
                                    个人设置
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                    <el-icon><SwitchButton /></el-icon>
                                    退出登录
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </div>
            </el-header>
            <el-container class="content-container">
                <el-aside width="240px" class="main-aside">
                    <el-menu 
                        active-text-color="#409EFF" 
                        background-color="#001529" 
                        class="el-menu-vertical"
                        :default-active="activeMenu" 
                        text-color="#ffffff" 
                        router
                        @select="handleSelect"
                    >
                        <el-sub-menu index="HealthManager">
                            <template #title>
                                <el-icon>
                                    <User />
                                </el-icon>
                                <span>健康管家</span>
                            </template>
                            <el-menu-item index="/DailyCare">
                                <template #title>
                                    <el-icon>
                                        <Edit />
                                    </el-icon>
                                    <span>日常护理</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item index="/CareRecord">
                                <template #title>
                                    <el-icon>
                                        <Back />
                                    </el-icon>
                                    <span>护理记录</span>
                                </template>
                            </el-menu-item>
                        </el-sub-menu>
                        <el-sub-menu index="UserManagement">
                            <template #title>
                                <el-icon>
                                    <House />
                                </el-icon>
                                <span>用户管理</span>
                            </template>
                            <el-menu-item index="/OutboundCustomerList">
                                <template #title>
                                    <el-icon>
                                        <DataLine />
                                    </el-icon>
                                    <span>外出登记</span>
                                </template>
                            </el-menu-item>
                            <el-menu-item index="/CheckOutRegistration">
                                <template #title>
                                    <el-icon>
                                        <Grid />
                                    </el-icon>
                                    <span>退住登记</span>
                                </template>
                            </el-menu-item>
                        </el-sub-menu>
                        <el-sub-menu index="AI1">
                          <template #title>
                                <el-icon>
                                    <Avatar />
                                </el-icon>
                                <span>AI服务</span>
                            </template>
                            <el-menu-item index="/AI1">
                                <template #title>
                                    <el-icon>
                                        <DataBoard />
                                    </el-icon>
                                    <span>AI服务</span>
                                </template>
                            </el-menu-item>
                        </el-sub-menu>
                    </el-menu>
                </el-aside>
                <el-main class="main-content">
                    <div class="content-wrapper">
                        <router-view/>
                    </div>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>


<script setup>
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { jwtDecode } from 'jwt-decode'

// 导入Element Plus图标
import {
  WindPower, User, Edit, Back, Promotion,
  KnifeFork, Calendar, House, DataLine, Grid,
  FirstAidKit, Star, List, Setting, Notebook,
  Opportunity, UserFilled, Bell, Avatar, DataBoard,
  SwitchButton
} from '@element-plus/icons-vue'

const route = useRoute()
const activeMenu = ref('')
const userName=ref('')

// 监听路由变化，更新激活菜单
watch(() => route.path, (newPath) => {
  activeMenu.value = newPath
}, { immediate: true })

const handleSelect = (key, keyPath) => {
  console.log(key, keyPath)
}

const handleClick = () => {
  console.log('click')
}

const init = ()=>{
	let token=sessionStorage.getItem('token');
	const payload = jwtDecode(token);
	const user = JSON.parse(payload.mobileJson)
	userName.value=user.realName;
}
init();
</script>


<style scoped>
.main-container {
  height: 100vh;
  background: #f0f2f5;
}

.main-header {
  background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  position: relative;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  color: #ffffff;
  animation: rotate 20s linear infinite;
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.system-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: #ffffff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-right {
  display: flex;
  align-items: center;
}

.user-dropdown {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.user-dropdown:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.content-container {
  height: calc(100vh - 64px);
}

.main-aside {
  background: #001529;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
}

.el-menu-vertical {
  border-right: none;
  height: 100%;
}

.el-menu-vertical ::v-deep .el-sub-menu__title {
  height: 50px;
  line-height: 50px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.el-menu-vertical ::v-deep .el-sub-menu__title:hover {
  background-color: #1890ff !important;
  color: #ffffff !important;
}

.el-menu-vertical ::v-deep .el-menu-item {
  height: 45px;
  line-height: 45px;
  font-size: 13px;
  padding-left: 48px !important;
  transition: all 0.3s ease;
}

.el-menu-vertical ::v-deep .el-menu-item:hover {
  background-color: #1890ff !important;
  color: #ffffff !important;
  transform: translateX(4px);
}

.el-menu-vertical ::v-deep .el-menu-item.is-active {
  background-color: #1890ff !important;
  color: #ffffff !important;
  border-right: 3px solid #52c41a;
}

.el-menu-vertical ::v-deep .el-sub-menu.is-active .el-sub-menu__title {
  color: #ffffff !important;
}

.main-content {
  padding: 0;
  background: #f0f2f5;
  overflow-y: auto;
}

.content-wrapper {
  padding: 24px;
  min-height: 100%;
  background: #ffffff;
  margin: 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* 滚动条样式 */
.main-aside::-webkit-scrollbar,
.main-content::-webkit-scrollbar {
  width: 6px;
}

.main-aside::-webkit-scrollbar-track,
.main-content::-webkit-scrollbar-track {
  background: transparent;
}

.main-aside::-webkit-scrollbar-thumb,
.main-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.main-aside::-webkit-scrollbar-thumb:hover,
.main-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-header {
    padding: 0 16px;
  }
  
  .system-title {
    font-size: 16px;
  }
  
  .main-aside {
    width: 200px !important;
  }
  
  .content-wrapper {
    margin: 8px;
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .logo-section {
    gap: 8px;
  }
  
  .system-title {
    font-size: 14px;
  }
  
  .main-aside {
    width: 180px !important;
  }
}
</style>